package com.ncs.nc.mq;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class MqRabbitConnectionUtil {
    //待连接的MQ主机，此处为本地连接
    private static final String HOST="127.0.0.1";
    //MQ的端口号为5672
    private static final int PORT=5672;
    //访问MQ的用户名
    private static final String USER_NAME="guest";
    //用户密码
    private static final String PASSWORD="guest";

    //获取连接到RabbitMQ服务的链接
    public static Connection getConnection() throws IOException, TimeoutException {
        ConnectionFactory factory=new ConnectionFactory();
        factory.setHost(HOST);
        factory.setPort(PORT);
        factory.setUsername(USER_NAME);
        factory.setPassword(PASSWORD);
        return factory.newConnection();
    }
}
